/**************************************************
|	File:		SoundManager.cpp
|	Author:		Benjamin Budian
|	Course:		SGD
|	Purpose:	SoundManager holds on to and distributes appropriate sound identifiers
|				
**************************************************/

//Local Includes
#include "SoundManager.h"
#include "Entity.h"

//Wrappers
#include "../SGD Wrappers/CSGD_XAudio2.h"

SoundManager::SoundManager(void){}
SoundManager::~SoundManager(void){}

SoundManager* SoundManager::GetInstance(){
	static SoundManager sInstance;
	return &sInstance;
}

void SoundManager::Initialize() //Parameters to come
{
	m_nBowShotID			= CSGD_XAudio2::GetInstance()->SFXLoadSound(_T("resource\\sounds\\Weapon\\bb_Bow_Fire_Arrow.wav"));
	m_nSwordSwingID			= CSGD_XAudio2::GetInstance()->SFXLoadSound(_T("resource\\sounds\\Weapon\\bb_Sword_Swoosh.wav"));
	m_nSwordSheathID		= CSGD_XAudio2::GetInstance()->SFXLoadSound(_T("resource\\sounds\\Weapon\\bb_sword-sheath.wav"));

	m_nPlayerHitID			= CSGD_XAudio2::GetInstance()->SFXLoadSound(_T("resource\\sounds\\Weapon\\bb_stab.wav"));
	m_nEnemyHitID			= CSGD_XAudio2::GetInstance()->SFXLoadSound(_T("resource\\sounds\\bb_enemy-hit.wav"));
	m_nPlayerDeathID		= CSGD_XAudio2::GetInstance()->SFXLoadSound(_T("resource\\sounds\\bb_death-scream.wav"));
	m_nEnemyDeathID			= CSGD_XAudio2::GetInstance()->SFXLoadSound(_T("resource\\sounds\\bb_deaths.wav"));
	
	m_nBackgroundMusicID	= CSGD_XAudio2::GetInstance()->MusicLoadSong(_T("resource\\sounds\\bb_background_music.xwm"));
	m_nAmbientSoundID1		= CSGD_XAudio2::GetInstance()->SFXLoadSound(_T("resource\\sounds\\Ambient\\bb_nightmare-soundscape1.wav"));
	m_nAmbientSoundID2		= CSGD_XAudio2::GetInstance()->SFXLoadSound(_T("resource\\sounds\\Ambient\\bb_nightmare-soundscape2.wav"));
	m_nAmbientSoundID3		= CSGD_XAudio2::GetInstance()->SFXLoadSound(_T("resource\\sounds\\Ambient\\bb_ambient-darkness.wav"));
	m_nVictorySFXID			= CSGD_XAudio2::GetInstance()->SFXLoadSound(_T("resource/sounds/bb_victory.wav"));

}

void SoundManager::Shutdown(){

	CSGD_XAudio2::GetInstance()->SFXUnloadSound(m_nBowShotID)		;
	CSGD_XAudio2::GetInstance()->SFXUnloadSound(m_nSwordSwingID	)	;
	CSGD_XAudio2::GetInstance()->SFXUnloadSound(m_nSwordSheathID)	;
	
	CSGD_XAudio2::GetInstance()->SFXUnloadSound(m_nPlayerHitID)		;
	CSGD_XAudio2::GetInstance()->SFXUnloadSound(m_nEnemyHitID)		;
	CSGD_XAudio2::GetInstance()->SFXUnloadSound(m_nPlayerDeathID)	;
	CSGD_XAudio2::GetInstance()->SFXUnloadSound(m_nEnemyDeathID	)	;
	
	CSGD_XAudio2::GetInstance()->MusicUnloadSong(m_nBackgroundMusicID);
	CSGD_XAudio2::GetInstance()->SFXUnloadSound(m_nAmbientSoundID1);
	CSGD_XAudio2::GetInstance()->SFXUnloadSound(m_nAmbientSoundID2);
	CSGD_XAudio2::GetInstance()->SFXUnloadSound(m_nAmbientSoundID3);

	m_nBowShotID			=	-1;
	m_nSwordSwingID			=	-1;
	m_nSwordSheathID		=	-1;

	m_nPlayerHitID			=	-1;
	m_nEnemyHitID			=	-1;
	m_nPlayerDeathID		=	-1;
	m_nEnemyDeathID			=	-1;

	m_nBackgroundMusicID	=	-1;
	m_nAmbientSoundID1		=	-1;
	m_nAmbientSoundID2		=	-1;
	m_nAmbientSoundID3		= 	-1;
}

int SoundManager::GetSoundID( SoundIDClassifier eSound )
{
	switch( eSound ){
	case BOW_SHOT:
		return m_nBowShotID;
		break;
	case SWORD_SWING:
		return m_nSwordSwingID;
		break;
	case SWORD_SHEATH:
		return m_nSwordSheathID;
		break;
	case ENEMY_HIT:
		return m_nEnemyHitID;
		break;
	case PLAYER_HIT:
		return m_nPlayerHitID;
		break;
	case PLAYER_DEATH:
		return m_nPlayerDeathID;
		break;
	case ENEMY_DEATH:
		return m_nEnemyDeathID;
		break;
	case BACKGROUND_MUSIC:
		return m_nBackgroundMusicID;
		break;
	case AMBIENT_EFFECT:
		{
			int random_effect = rand() % 3;

			if(random_effect == 0)
				return m_nAmbientSoundID1;
			else if(random_effect == 1)
				return m_nAmbientSoundID2;
			else 
				return m_nAmbientSoundID3;
		}
		break;
	case VICTORY:
		return m_nVictorySFXID;
		break;
	default:
		return -1;
	}
	
}

